<?php

defined( 'IN_DICE' ) or die( 'Access Error!' );

class user extends control {

  public function __construct() {
    
  }

  /**
   * 游戏初始化
   */
  public function login( $req ) {
    $this->auth( $req, 0 );
    if( $this->check != 1 ) { return $this->genRes(); }

    $daybonus = $vipbonus = $toolbonus = 0;
    $aU = model::member()->getpbyuid( $this->uid, false ); //获得用户信息
    $aG = model::member()->get( $this->uid, false ); //获得用户游戏信息
    $ctime = strtotime('today'); //判断用户昨天是否登陆过
    $iscday = ( ( $aG['ugtime'] >= $ctime - 24*60*60 ) && $aG['ugtime'] < $ctime ); //是否连续登录
    if( ( date( 'Ymd', $aG['ugtime'] ) != date( 'Ymd', time() ) ) 
        && model::member()->uplogintime( $this->uid, $iscday ) ) {
      $aG['uldays'] = $iscday ? $aG['uldays'] + 1 : 1;
      //VIP送钱
      //道具卡送钱
      //如果是直接给钱的模式则送每日登陆奖励
    }
    $aO = model::online()->get( $this->uid ); //查询用户是否断线重连
    $ret = array( //返回给客户端的数据
        0 => array(//用户基本信息
            $this->uid,
            $aU['puid'],
            $aU['usid'],
            $aU['uname'],
            $aU['uface'],
            $aU['usex'],
        ),
        1 => array(//用户游戏数据,按此顺序返回,不可改顺序
            $aG['uchip'],
            $aG['ulevel'],
            $aG['uexp'],
            $aG['uvip'],
            $aG['ugift'],
            max(1, $aG['uldays']),
            $aG['uscore'],
            $aG['ustatus'],
        ),
        2 => array(//用户的奖励部分,每日登陆,VIP奖励,道具奖励
            (int) $daybonus,
            (int) $vipbonus,
            (int) $toolbonus,
        )
    );

    $this->error = 1;
    return $this->genRes( $ret );
  }

  /**
   * 获取用户的详细游戏资料
   */
  public function get( $req ) {
    $this->auth( $req, 0 );
    if( $this->check != 1 ) { return $this->genRes(); }
    list( $uid ) = $this->param;
    $this->error = 1;
    $aG = model::member()->get( $uid ? $uid : $this->uid, false );
    $ret = array(
        $aG['uid'],
        $aG['uchip'],
        $aG['ulevel'],
        $aG['uexp'],
        $aG['uvip'],
        $aG['ugift'],
        $aG['uldays'],
        $aG['uscore'],
        $aG['ustatus'],
        //$aG[''],
        );
    return $this->genRes( $ret );
  }

}
